/**
 * Created With IntelliJ IDEA
 * Description:牛客网：BM29 二叉树中和为某一值的路径(一)
 * <a href="https://www.nowcoder.com/practice/508378c0823c423baa723ce448cbfd0c?tpId=295&tqId=634&ru=/exam/oj&qru=/ta/format-top101/question-ranking&sourceUrl=%2Fexam%2Foj">...</a>
 * User: DELL
 * Data: 2022-11-27
 * Time: 23:20
 */
import java.util.*;

 class TreeNode {
      int val = 0;
      TreeNode left = null;
     TreeNode right = null;
 }


public class Solution {
    public boolean hasPathSum (TreeNode root, int sum) {
        //空节点无路径
        if (root == null) {
            return false;
        }
        if (root.left == null && root.right == null && sum == root.val) {
            return true;
        } else {
            return hasPathSum(root.left,sum - root.val) || hasPathSum(root.right,sum - root.val);
        }
    }
}
